#include "contentsearcher.h"
#include <QProcess>
#include <QStandardItem>
#include <QApplication>
#include <QClipboard>
#include <QUrl>
#include <QMessageBox>
#include <QPrintDialog>
#include <QXmlStreamWriter>
#include <QFileDialog>
#include <QTextDocument>
#include <QPainter>
#include <QPrinter>
#include <QDesktopServices>
#include <QObject>
#include <QThread>
#include <QFuture>
#include <QtCore>
#include <QProgressDialog>


ContentSearcher::ContentSearcher(QWidget *parent, Qt::WFlags flags)
	: QMainWindow(parent, flags)
{
	ui_main.setupUi(this);

	m_pDialogReplace = new QDialog(this);
	ui_dialog_replace.setupUi(m_pDialogReplace);

	m_nProgressCnt = 0;
	m_nTotalMatch = 0;	
	m_nTotalSearchFiles = 0;
	m_nTotalMatchInFiles = 0; 

	m_pResultModel = new QStandardItemModel(this);
	ui_main.treeView_searchResult->setModel(m_pResultModel);

	m_pHTMLTextDelegate = new HtmlTextDelegate(this);
	ui_main.treeView_searchResult->setItemDelegate(m_pHTMLTextDelegate);
	ui_dialog_replace.listView->setItemDelegate(m_pHTMLTextDelegate);

	m_pMessageDeliver = new MessageDeliver(this);
	m_pOperationHandler = new OperationHandler(this, m_pMessageDeliver);
	m_pOperationHandler->setPriority(QThread::TimeCriticalPriority);

	m_pDialogOption = new QDialog(this);
	ui_dialog_option.setupUi(m_pDialogOption);
	m_pDialogOption->setFixedSize(m_pDialogOption->size());
	

	m_pLabelStatus = new QLabel(tr("Ready"), this);
	m_pProgressBar = new QProgressBar(this);
	m_pPushButtonStop = new QPushButton(tr("Stop"), this);
	m_pLabelProcess = new QLabel(this);

	m_pLabelStatus->setFixedSize(50, 20);
	m_pProgressBar->setFixedSize(200, 20);
	m_pPushButtonStop->setFixedSize(40, 28);
	m_pLabelProcess->setFixedSize(650, 20);

	ui_main.statusBar->addWidget(m_pLabelStatus);
	ui_main.statusBar->addWidget(m_pProgressBar);
	ui_main.statusBar->addWidget(m_pPushButtonStop);
	ui_main.statusBar->addWidget(m_pLabelProcess);

	m_pProgressBar->setVisible(false);
	m_pPushButtonStop->setVisible(false);
	m_pLabelProcess->setVisible(false);


	m_pMenuRightClick = new QMenu(this);
	m_pActionExtAppOpen = new QAction(tr("Open with default application(&D)"), m_pMenuRightClick);
	m_pActionPrint = new QAction(tr("Print(&P)"), m_pMenuRightClick);
	m_pActionCopy = new QAction(tr("Copy to clip board(&C)"), m_pMenuRightClick);
	m_pActionNotePadOpen = new QAction(tr("Open in notepad(&N)"), m_pMenuRightClick);
	m_pActionExpXml = new QAction(tr("Export to XML(&X)"), m_pMenuRightClick);
	m_pMenuRightClick->addAction(m_pActionExtAppOpen);
	m_pMenuRightClick->addAction(m_pActionNotePadOpen);
	m_pMenuRightClick->addAction(m_pActionCopy);
	m_pMenuRightClick->addAction(m_pActionPrint);
	m_pMenuRightClick->addAction(m_pActionExpXml);


	connect(ui_main.toolButton_path, SIGNAL(clicked()), this, SLOT(setSearchPath()));
	connect(ui_main.pushButton_search, SIGNAL(clicked()), this, SLOT(doSearch()));
	connect(ui_main.action_search, SIGNAL(triggered()), this, SLOT(doSearch()));
	connect(ui_main.pushButton_replace, SIGNAL(clicked()), this, SLOT(doReplace()));
	connect(ui_main.action_exit, SIGNAL(triggered()), this, SLOT(close()));
	connect(ui_main.pushButton_subfolder, SIGNAL(clicked()), ui_main.action_subfolder, SLOT(toggle()));
	connect(ui_main.action_subfolder, SIGNAL(triggered()), ui_main.pushButton_subfolder, SLOT(toggle()));
	connect(ui_main.pushButton_captital, SIGNAL(clicked()), ui_main.action_captial, SLOT(toggle()));
	connect(ui_main.action_captial, SIGNAL(triggered()), ui_main.pushButton_captital, SLOT(toggle()));
	connect(ui_main.action_option, SIGNAL(triggered()), m_pDialogOption, SLOT(open()));

	connect(ui_main.treeView_searchResult, SIGNAL(doubleClicked(const QModelIndex&)), this, SLOT(notePadOpen(const QModelIndex&)));
	connect(ui_main.treeView_searchResult, SIGNAL(rightClicked(const QModelIndex&)), this , SLOT(showRightClickMenu(const QModelIndex&)));
	ui_main.treeView_searchResult->setAllColumnsShowFocus(true);

	connect(m_pActionExtAppOpen, SIGNAL(triggered()), this, SLOT(extAppOpen()));
	connect(m_pActionNotePadOpen, SIGNAL(triggered()), this, SLOT(notePadOpen()));
	connect(m_pActionCopy, SIGNAL(triggered()), this, SLOT(copyToClipboard()));
	connect(m_pActionPrint, SIGNAL(triggered()), this, SLOT(printSelectedItem()));
	connect(m_pActionExpXml, SIGNAL(triggered()), this, SLOT(expToXml()));

	connect(ui_dialog_replace.pushButton_replaceAll, SIGNAL(clicked()), this, SLOT(replaceThis()));
	connect(ui_dialog_replace.pushButton_replaceDir, SIGNAL(clicked()), this, SLOT(replaceThis()));
	connect(ui_dialog_replace.pushButton_replaceFile, SIGNAL(clicked()), this, SLOT(replaceThis()));
	connect(ui_dialog_replace.pushButton_replaceThis, SIGNAL(clicked()), this, SLOT(replaceThis()));
	connect(ui_dialog_replace.pushButton_skipAll, SIGNAL(clicked()), this, SLOT(skipThis()));
	connect(ui_dialog_replace.pushButton_skipDir, SIGNAL(clicked()), this, SLOT(skipThis()));
	connect(ui_dialog_replace.pushButton_skipFile, SIGNAL(clicked()), this, SLOT(skipThis()));
	connect(ui_dialog_replace.pushButton_skipThis, SIGNAL(clicked()), this, SLOT(skipThis()));

	connect(ui_dialog_replace.pushButton_replaceThis, SIGNAL(clicked()), this, SLOT(replaceThis()));
	connect(ui_dialog_replace.pushButton_skipThis, SIGNAL(clicked()), this, SLOT(skipThis()));
	connect(m_pDialogReplace, SIGNAL(rejected()), this, SLOT(setSkipAll()));

	connect(ui_dialog_option.pushButton_textEditor, SIGNAL(clicked()), this, SLOT(setTxtEditorPath()));
	connect(ui_dialog_option.pushButton_binaryEditor, SIGNAL(clicked()), this, SLOT(setBinEditorPath()));

	connect(m_pMessageDeliver, SIGNAL(txUpdateResultLabel(const QString&)), this, SLOT(updateResultLabel(const QString&)));
	connect(m_pMessageDeliver, SIGNAL(txUpdateCompletedItem(QStandardItem*)), this, SLOT(updateCompletedItem(QStandardItem*)));
	connect(m_pMessageDeliver, SIGNAL(txSearchReplaceCompleted(QString)), this, SLOT(searchReplaceCompleted(QString)), Qt::BlockingQueuedConnection);
	connect(m_pMessageDeliver, SIGNAL(txOtherOperationCompleted()), this, SLOT(otherOperationCompleted()), Qt::BlockingQueuedConnection);
	connect(m_pMessageDeliver, SIGNAL(txPopUpWarning(const QString&, const QString&)), this, SLOT(popUpWarning(const QString&, const QString&)), Qt::BlockingQueuedConnection);
	connect(m_pMessageDeliver, SIGNAL(txPopUpReplace(QStandardItemModel*)), this, SLOT(popUpReplace(QStandardItemModel*)), Qt::BlockingQueuedConnection);
	connect(m_pMessageDeliver, SIGNAL(txPopUpQuestion(const QString&, const QString&)), this, SLOT(popUpQuestion(const QString&, const QString&)), Qt::BlockingQueuedConnection);
	connect(m_pMessageDeliver, SIGNAL(txUpdateFailedItem(QString)), this, SLOT(updateFailedItem(QString)));
	connect(m_pMessageDeliver, SIGNAL(txInitialProgressRange(const int)), this, SLOT(initialProgressRange(const int)), Qt::BlockingQueuedConnection);
	connect(m_pMessageDeliver, SIGNAL(txUpdateProgressBar(const int, const QString&)), this, SLOT(updateProgressBar(const int, const QString&)));

	connect(ui_dialog_replace.pushButton_replaceAll, SIGNAL(clicked()), m_pOperationHandler, SLOT(setReplaceAll()));
	connect(ui_dialog_replace.pushButton_replaceDir, SIGNAL(clicked()), m_pOperationHandler, SLOT(setReplaceDir()));
	connect(ui_dialog_replace.pushButton_replaceFile, SIGNAL(clicked()), m_pOperationHandler, SLOT(setReplaceFile()));
	connect(ui_dialog_replace.pushButton_skipAll, SIGNAL(clicked()), m_pOperationHandler, SLOT(setSkipAll()));
	connect(ui_dialog_replace.pushButton_skipDir, SIGNAL(clicked()), m_pOperationHandler, SLOT(setSkipDir()));
	connect(ui_dialog_replace.pushButton_skipFile, SIGNAL(clicked()), m_pOperationHandler, SLOT(setSkipFile()));
	connect(m_pPushButtonStop, SIGNAL(clicked()), m_pOperationHandler, SLOT(stop()));
	connect(this, SIGNAL(stopAll()), m_pOperationHandler, SLOT(stop()));
	
}

ContentSearcher::~ContentSearcher()
{

}

void ContentSearcher::closeEvent(QCloseEvent * event)
{
	emit stopAll();
}

void ContentSearcher::initialProgressRange(const int maximum)
{
	m_nPendingFiles = maximum;
	m_pProgressBar->setRange(0, maximum);
}

void ContentSearcher::updateFailedItem(const QString strFail)
{
	QStandardItem *item = new QStandardItem;
	item->setText(strFail);
	m_pResultModel->appendRow(item);
}

void ContentSearcher::popUpReplace(QStandardItemModel *model)
{
	if (model == nullptr)
	{
		return;
	}
	m_pDialogReplace->setWindowTitle(model->item(0)->accessibleText());
	ui_dialog_replace.listView->setModel(model);
	int ret = m_pDialogReplace->exec();
	m_pMessageDeliver->getReply(ret);
}

void ContentSearcher::popUpQuestion(const QString &title, const QString &content)
{
	QMessageBox::StandardButton reply;
	reply = QMessageBox::question(NULL, tr("ContentSeacher"), tr("Confirm to replace?"), 
		QMessageBox::Yes|QMessageBox::No|QMessageBox::YesToAll|QMessageBox::NoToAll);

	if	(reply == QMessageBox::Yes)
	{
		m_pMessageDeliver->getReply(1);
	}
	else if (reply == QMessageBox::YesToAll)
	{
		m_pMessageDeliver->getReply(2);
	}
	else if (reply == QMessageBox::NoToAll)
	{
		m_pMessageDeliver->getReply(3);
	}
	else
	{
		m_pMessageDeliver->getReply(0);
	}
}

void ContentSearcher::popUpWarning(const QString &title, const QString &content)
{
	QMessageBox::warning(NULL, title, content);
}

void ContentSearcher::otherOperationCompleted()
{
	m_pProgressBar->setVisible(false);
	m_pLabelProcess->setVisible(false);
	m_pPushButtonStop->setVisible(false);
	m_pLabelStatus->setText(tr("Ready"));

	ui_main.pushButton_search->setEnabled(true);
	ui_main.pushButton_replace->setEnabled(true);
	ui_main.pushButton_captital->setEnabled(true);
	ui_main.pushButton_subfolder->setEnabled(true);
	ui_main.action_replace->setEnabled(true);
	ui_main.action_search->setEnabled(true);
	ui_main.action_captial->setEnabled(true);
	ui_main.action_subfolder->setEnabled(true);
}

void ContentSearcher::searchReplaceCompleted(QString string /* = 0 */)
{
	if(!string.isEmpty()){
		m_pProgressBar->setVisible(false);
		m_pLabelProcess->setVisible(false);
		m_pPushButtonStop->setVisible(false);

		QString result = string.arg(m_nTotalSearchFiles).arg(m_nTotalMatch).arg(m_nTotalMatchInFiles);
		QStandardItem* tailItem = new QStandardItem(result);
		tailItem->setAccessibleText(result.toLocal8Bit());
		tailItem->setSelectable(false);
		m_pResultModel->appendRow(tailItem);
		ui_main.label_result->setText(result);
		m_pLabelStatus->setText(tr("Ready"));
	}

	ui_main.pushButton_search->setEnabled(true);
	ui_main.pushButton_replace->setEnabled(true);
	ui_main.pushButton_captital->setEnabled(true);
	ui_main.pushButton_subfolder->setEnabled(true);
	ui_main.action_replace->setEnabled(true);
	ui_main.action_search->setEnabled(true);
	ui_main.action_captial->setEnabled(true);
	ui_main.action_subfolder->setEnabled(true);
}

void ContentSearcher::updateResultLabel(const QString &string)
{
	ui_main.label_result->setText(string);
}

void ContentSearcher::updateProgressBar(const int i, const QString &string)
{
	m_pProgressBar->setValue(i);
	m_pLabelProcess->setText(string);
}

void ContentSearcher::updateCompletedItem(QStandardItem *item)
{
	if (item == nullptr)
	{
		return;
	}
	m_nProgressCnt++;
	m_pProgressBar->setValue(m_nProgressCnt);
	QString labelSearhing = tr("Pending search %1").arg(m_nPendingFiles--);
	int times = 0;
	while (times < m_nProgressCnt%3 )
	{
		labelSearhing.append(".");
		times++;
	}
	ui_main.label_result->setText(labelSearhing);
	m_pLabelProcess->setText(item->text());

	if (item->rowCount() > 0)
	{
		m_pResultModel->appendRow(item);
		ui_main.treeView_searchResult->expandAll();
		m_nTotalMatch += item->rowCount();
		m_nTotalMatchInFiles++;
		m_nTotalSearchFiles++;
	}
	else
	{
		m_nTotalSearchFiles++;
		delete item;
	}
	
}

void ContentSearcher::replaceThis()
{
	emit m_pDialogReplace->done(1);
}

void ContentSearcher::skipThis()
{
	emit m_pDialogReplace->done(-1);
}


void ContentSearcher::expToXml()
{
	QString path = QFileDialog::getSaveFileName(this, NULL, NULL, "*.xml", NULL);
	if (!path.isEmpty())
	{
		if (m_pOperationHandler->setExportXMLParameter(path, m_pResultModel))
		{
			m_pOperationHandler->start();

			m_pLabelStatus->setText(tr("Export"));
			ui_main.pushButton_search->setEnabled(false);
			ui_main.pushButton_replace->setEnabled(false);
			ui_main.pushButton_captital->setEnabled(false);
			ui_main.pushButton_subfolder->setEnabled(false);
			ui_main.action_replace->setEnabled(false);
			ui_main.action_search->setEnabled(false);
			ui_main.action_captial->setEnabled(false);
			ui_main.action_subfolder->setEnabled(false);
			m_pProgressBar->setValue(0);
			m_pProgressBar->setVisible(true);
			m_pLabelProcess->setText("");
			m_pLabelProcess->setVisible(true);
			m_pPushButtonStop->setVisible(true);
		}
		else
		{	
			searchReplaceCompleted();
			return;
		}
	}
	else
	{
		// TODO: exception handle.
	}
}

void ContentSearcher::printSelectedItem()
{
	QPrintDialog printDialog;
	if(!printDialog.exec())
	{
		return;
	}

	if (m_pOperationHandler->setPrintResultParameter(m_pResultModel))
	{
		m_pOperationHandler->start();

		m_pLabelStatus->setText(tr("Print"));
		ui_main.pushButton_search->setEnabled(false);
		ui_main.pushButton_replace->setEnabled(false);
		ui_main.pushButton_captital->setEnabled(false);
		ui_main.pushButton_subfolder->setEnabled(false);
		ui_main.action_replace->setEnabled(false);
		ui_main.action_search->setEnabled(false);
		ui_main.action_captial->setEnabled(false);
		ui_main.action_subfolder->setEnabled(false);
		m_pProgressBar->setValue(0);
		m_pProgressBar->setVisible(true);
		m_pLabelProcess->setText("");
		m_pLabelProcess->setVisible(true);
		m_pPushButtonStop->setVisible(true);
	}
	else
	{	
		searchReplaceCompleted();
	}
}

void ContentSearcher::copyToClipboard()
{
	QStandardItem *item = m_pResultModel->itemFromIndex(m_pSelectedModelIndex);
	QApplication::clipboard()->setText(item->accessibleText());
}

void ContentSearcher::extAppOpen()
{
	QStandardItem *item = m_pResultModel->itemFromIndex(m_pSelectedModelIndex);
	if(item == nullptr || !item->isSelectable())
	{
		return;
	}
	
	if(item->hasChildren())
	{
		QDesktopServices::openUrl(QUrl(QString("file:///%1").arg(item->accessibleText()), QUrl::TolerantMode));
	}else{

		QStandardItem *parentItem;
		parentItem = item->parent();
		QString filePath = parentItem->text();
		QDesktopServices::openUrl(QUrl(QString("file:///%1").arg(parentItem->accessibleText()), QUrl::TolerantMode));
	}
}

void ContentSearcher::notePadOpen()
{
	notePadOpen(m_pSelectedModelIndex);
}

void ContentSearcher::notePadOpen(const QModelIndex& index)
{
	if(ui_dialog_option.lineEdit_textEditor->text().isEmpty())
	{
		QMessageBox::warning(NULL, tr("ContentSeacher"), tr("Notepad path can't be empty !"));
		return;
	}

	QProcess process(this);
	QStringList args;
	int ret;

	QStandardItem *item = m_pResultModel->itemFromIndex(index);
	if(item == nullptr)
	{
		return;
	}
	if(!item->isSelectable())
	{
		return;
	}

	if(item->hasChildren())
	{
		QString filePath = item->accessibleText();
		args.push_back(filePath);
		ret = process.execute(ui_dialog_option.lineEdit_textEditor->text(), args); 
	}else
	{
		QStandardItem *parentItem;
		parentItem = item->parent();
		QString filePath = parentItem->accessibleText();
		args.push_back(filePath);
		ret = process.execute(ui_dialog_option.lineEdit_textEditor->text(), args); 
	}
	if(ret == -2)
	{
		QMessageBox::warning(NULL, tr("ContentSeacher"), tr("Can't open with notepad, please check the notepad path setting"));
	}if(ret == -1)
	{
		QMessageBox::warning(NULL, tr("ContentSeacher"), tr("Open with notepad failed "));
	}
}

void ContentSearcher::showRightClickMenu(const QModelIndex& index)
{
	QStandardItem *item = m_pResultModel->itemFromIndex(index);

	m_pActionExtAppOpen->setEnabled(true);
	m_pActionCopy->setEnabled(true);
	m_pActionNotePadOpen->setEnabled(true);
	m_pActionExpXml->setEnabled(true);
	m_pActionPrint->setEnabled(true);

	if(item == nullptr || !item->isSelectable())
	{
		m_pActionExtAppOpen->setDisabled(true);
		m_pActionCopy->setDisabled(true);
		m_pActionNotePadOpen->setDisabled(true);
	}
	if(m_pResultModel->rowCount() <= 0 || !item->isSelectable())
	{
		m_pActionExpXml->setDisabled(true);
		m_pActionPrint->setDisabled(true);
	}
	m_pSelectedModelIndex = index;
	m_pMenuRightClick->exec(QCursor::pos());
}

void ContentSearcher::setSearchPath()
{
	QString path = QFileDialog::getExistingDirectory(this, NULL, NULL, QFileDialog::ShowDirsOnly);
	ui_main.lineEdit_path->setText(path);
}

void ContentSearcher::setTxtEditorPath()
{
	QString path = QFileDialog::getOpenFileName(this, NULL, NULL, "*.exe", NULL);
	ui_dialog_option.lineEdit_textEditor->setText(path);
	m_pDialogOption->raise();
	m_pDialogOption->setFocus();
}

void ContentSearcher::setBinEditorPath()
{
	QString path = QFileDialog::getOpenFileName(this, NULL, NULL, "*.exe", NULL);
	ui_dialog_option.lineEdit_binaryEditor->setText(path);
	m_pDialogOption->raise();
	m_pDialogOption->setFocus();
}

void ContentSearcher::doSearch()
{
	if(m_pMessageDeliver == nullptr)
	{
		// TODO: exception handle.
		return;
	}

	m_pResultModel->clear();

	QDir dir;
	QDir::Filters filter = QDir::Hidden | QDir::NoSymLinks | QDir::NoDotAndDotDot;

	if(ui_main.pushButton_subfolder->isChecked())
	{
		filter |= QDir::AllEntries;
	}else
	{
		filter |= QDir::Files;
	}
	dir.setFilter(filter);
	dir.setSorting(QDir::Unsorted | QDir::Reversed);

	if(ui_main.lineEdit_searchContent->text().isEmpty())
	{
		QMessageBox::warning(NULL, tr("ContentSeacher"), tr("Please input search content first !"));
		return;
	}else if(ui_main.lineEdit_path->text().isEmpty())
	{
		QMessageBox::warning(NULL, tr("ContentSeacher"), tr("Search path can't be empty !"));
		return;
	}
	dir.setPath(ui_main.lineEdit_path->text());


	if(ui_main.lineEdit_filter->text().isEmpty())
	{
		ui_main.lineEdit_filter->setText("*");
	}
	

	m_nTotalMatch = 0;	
	m_nTotalSearchFiles = 0;
	m_nTotalMatchInFiles = 0; 
	m_nProgressCnt = 0;
	m_nPendingFiles = 0;
	m_pProgressBar->setValue(0);
	m_pLabelProcess->clear();

	ui_main.treeView_searchResult->expandAll();

	if (m_pOperationHandler->setSearchParameter(dir, ui_main.lineEdit_filter->text(), ui_main.lineEdit_searchContent->text(), ui_main.pushButton_captital->isChecked()))
	{
		m_pOperationHandler->start();

		m_pLabelStatus->setText(tr("Export"));
		ui_main.pushButton_search->setEnabled(false);
		ui_main.pushButton_replace->setEnabled(false);
		ui_main.pushButton_captital->setEnabled(false);
		ui_main.pushButton_subfolder->setEnabled(false);
		ui_main.action_replace->setEnabled(false);
		ui_main.action_search->setEnabled(false);
		ui_main.action_captial->setEnabled(false);
		ui_main.action_subfolder->setEnabled(false);
		m_pProgressBar->setValue(0);
		m_pProgressBar->setVisible(true);
		m_pLabelProcess->setText("");
		m_pLabelProcess->setVisible(true);
		m_pPushButtonStop->setVisible(true);

	}
	
}

void ContentSearcher::doReplace()
{
	if(m_pMessageDeliver == nullptr)
	{
		return;
	}

	m_pResultModel->clear();

	QDir dir;
	QDir::Filters filter = QDir::Hidden | QDir::NoSymLinks | QDir::NoDotAndDotDot;

	if(ui_main.pushButton_subfolder->isChecked())
	{
		filter |= QDir::AllEntries;
	}else
	{
		filter |= QDir::Files;
	}
	dir.setFilter(filter);
	dir.setSorting(QDir::Unsorted | QDir::Reversed);

	if(ui_main.lineEdit_searchContent->text().isEmpty())
	{
		QMessageBox::warning(NULL, tr("ContentSeacher"), tr("Please input search content first !"));
		searchReplaceCompleted();
		return;
	}else if(ui_main.lineEdit_path->text().isEmpty())
	{
		QMessageBox::warning(NULL, tr("ContentSeacher"), tr("Search path can't be empty !"));
		searchReplaceCompleted();
		return;
	}

	dir.setPath(ui_main.lineEdit_path->text());

	std::string inputContentPattern = ui_main.lineEdit_searchContent->text().toStdString();

	if(ui_main.lineEdit_filter->text().isEmpty())
	{
		ui_main.lineEdit_filter->setText("*");
	}

	if (m_pOperationHandler->setReplaceParameter(dir, ui_main.lineEdit_filter->text(), ui_main.lineEdit_searchContent->text(), ui_main.pushButton_captital->isChecked(), ui_main.lineEdit_replaceContent->text()))
	{
		ui_main.pushButton_search->setEnabled(false);
		ui_main.pushButton_replace->setEnabled(false);
		ui_main.pushButton_captital->setEnabled(false);
		ui_main.pushButton_subfolder->setEnabled(false);
		ui_main.action_replace->setEnabled(false);
		ui_main.action_search->setEnabled(false);
		ui_main.action_captial->setEnabled(false);
		ui_main.action_subfolder->setEnabled(false);

		m_pOperationHandler->start();
	}

}
